﻿/*
*   学员信息页面
*/
angular.module('jisuStuHome')
.controller('myQuestionController', ['$scope', '$rootScope', '$state', 'StuRequestTrain', 'interlocutionservice', 'sysUserInfo', 'Msg', 'MsgCon', 'T', 'LS', function ($scope, $rootScope, $state, ST, IS, sysUserInfo, Msg, MsgCon, T, LS) {


    //初始
    $scope.init = function () {
        $rootScope.parstr = "home.interlocution";
        $rootScope.twoparstr = "home.interlocution.myQuestion";
        //查询的参数
        $scope.params = {
            orgid: sysUserInfo.getuserinfo().organization_ID,
            userId: sysUserInfo.getuserinfo().user_ID,
            powerLV: sysUserInfo.getuserinfo().powerLV,
            searchText: "",
            pageIndex: 1,
            pageSize: 10
        };
        $scope.userInfo = sysUserInfo.getuserinfo(); //用户

    }

    //返回主页，专栏列表
    $scope.backHome = function () {
        $rootScope.twoparstr = "home.interlocution";
        $state.go($rootScope.twoparstr);
    }
    $scope.init();
    //返回列表
    //路由跳转详情页面
    $scope.openQuestInfo = function (item) {
        $rootScope.twoparstr = "home.interlocution.questiondetail";
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_ques', item);
        $state.go($rootScope.twoparstr);
    }
    /**********************************查询***********************************/

    $scope.getList = function (index) {
        ST.findProblemPage($scope.params).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.myQuesList = response.datas;
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("查询异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    /*********************************************************************/
    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            $scope.params.pageIndex = $scope.paginationConf.currentPage;
            $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
            $scope.getList();
        }
    };
    // 删除问答
    $scope.delQuestionInfo = function (item) {
        //提示框
        MsgCon.delnoicon().then(function (flag) {   // 删除弹框
            if (flag) {
                // 发送请求
                IS.delQA({ qaid: item.qaid, userid: sysUserInfo.getuserinfo().user_ID, colid: item.xid }).then(function (respose) {
                    if (respose.errorcode == "0") {
                        Msg.success("删除成功！");
                        $scope.getList();
                        //修改统计信息里的提问数量
                        if ($rootScope.TJInfo.askNum > 0) {
                            $rootScope.TJInfo.askNum = $rootScope.TJInfo.askNum - 1;
                        }
                    } else {
                        Msg.error("操作失败！");
                    }
                }, function errorCallback() {
                    console.log("连接服务器失败！");
                });
            }
        }, function (p) { console.log('error') });
    }
} ]);




